package com.feng.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;


//@EnableOpenApi
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    private boolean DEBUG = false;
    private static String PROD_BASE_URL = "www.lytxmd.com/api";
    private static String DEV_BASE_URL = "www.lytxmd.top/api";

    //配置了swagger的Docket 的 bean 实例
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(ApiInfo.DEFAULT);
    }

    //配置 swagger 信息 = apiInfo
//    private ApiInfo apiInfo() {
//        //作者信息
//        Contact contact = new Contact("zhangfeng", "https://www.zhangfeng.vip/", "236661283@qq.com");
//        return new ApiInfo("API文档",
//            "接口信息",
//            "v1.0",
//            "",
//            contact,
//            "Apache 2.0",
//            "http://www.apache.org/licenses/LICENSE-2.0",
//            new ArrayList());
//    }


//    @Bean
//    public Docket createRestApi() {
//        return new Docket(DocumentationType.SWAGGER_2)
////            .host(DEBUG?DEV_BASE_URL:PROD_BASE_URL)
//            .genericModelSubstitutes(DeferredResult.class)
//            .useDefaultResponseMessages(false)
//            .forCodeGeneration(false)
//            .pathMapping("/")
//            .select()
//            .apis(RequestHandlerSelectors.basePackage("com.feng.api"))
////                .apis(RequestHandlerSelectors.any())
////                .paths(PathSelectors.any())
//            .build()
////            .globalOperationParameters(setHeaderToken())//添加accessToken
//            .apiInfo(apiInfo());
////                .enable(true);
//    }
//    private ApiInfo apiInfo() {
//        return new ApiInfoBuilder()
//            .title("Feng Resful API Docs")
//            .description("API列表")
//            .version("1.0")
//            .build();
//    }
//
//    private List<Parameter> setHeaderToken() {
//        //添加head参数start
//        ParameterBuilder tokenPar = new ParameterBuilder();
//        List<Parameter> pars = new ArrayList<Parameter>();
//        Parameter build = tokenPar.name("Authorization")
//            //仅限测试使用,该Token有效期为7天
////            .defaultValue("eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImNyZWF0ZWQiOjE1MzAxNzU0NDAyODksImV4cCI6MTUzMDc4MDI0MH0.EvYkFeIojtiAYaGAm0b46YX7BhOMW3QRIgafr7aGtuQVetSBSx2ijXubvnnughntaVl3pkqCq2mpJDCa1awuDw")
//            .description("令牌")
//            .modelRef(new ModelRef("string"))
//            .parameterType("header")
//            .required(false)
//            .build();
//
//        Parameter openIdHeader = tokenPar.name("openId")
//            //仅限测试使用,该Token有效期为7天
////               .defaultValue("eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImNyZWF0ZWQiOjE1MzAxNzU0NDAyODksImV4cCI6MTUzMDc4MDI0MH0.EvYkFeIojtiAYaGAm0b46YX7BhOMW3QRIgafr7aGtuQVetSBSx2ijXubvnnughntaVl3pkqCq2mpJDCa1awuDw")
//            .description("微信openId")
//            .modelRef(new ModelRef("string"))
//            .parameterType("header")
//            .required(false)
//            .build();
//        pars.add(build);
//        pars.add(openIdHeader);
//        //添加head参数end
//        return pars;
//    }
}